﻿@inject IHttpService _httpService

@inject IDataCacheService _dataCacheService


<CnGalWebSite.Components.Containers.MiniModeContainer>
    <CnGalWebSite.Components.Containers.MasaTitleContainer Outline Title="最新编辑" Icon="@IconType.Edit.ToIconString()" Class="mb-4">
        <ButtonContent>

            <MButton Rounded Color="primary" OnClick="GetNewRandomList">
                <MIcon Left>mdi-refresh </MIcon>
                刷新
            </MButton>


        </ButtonContent>
        <ChildContent>
            <div class="row">
                @foreach (var item in Model)
                {
                    <div class="col-12 col-md-6 col-lg-4 mb-4">
                        @{
                            string name = item.RelatedName + " 编辑记录";
                            string context = string.IsNullOrWhiteSpace(item.RelatedName) ? ("Id：" + item.RelatedId) : item.RelatedName;
                            string url = "/" + item.Type switch
                            {
                                ExaminedNormalListModelType.Entry => "entries",
                                ExaminedNormalListModelType.Article => "articles",
                                ExaminedNormalListModelType.Tag => "tags",
                                ExaminedNormalListModelType.Disambig => "disambigs",
                                ExaminedNormalListModelType.Periphery => "peripheries",
                                ExaminedNormalListModelType.Video => "videos",
                                _=>""
                            } + "/index/" + item.RelatedId;
                            item.UserInfor.PersonalSignature = "对『" + context + "』" + item.Operation.GetDisplayName();
                        }
                         <CnGalWebSite.Shared.MasaComponent.Shared.Cards.Users.InfoCard Model="item.UserInfor" Href="@url" Class="w-100 h-100"/>

                    </div>
                }
            </div>
        </ChildContent>

    </CnGalWebSite.Components.Containers.MasaTitleContainer>

</CnGalWebSite.Components.Containers.MiniModeContainer>

@code {
    int ItemNum = 4;

    public List<ExaminedNormalListModel> Model { get; set; } = new List<ExaminedNormalListModel>();

    [Parameter]
    public bool IsTransverse { get; set; }
    [CascadingParameter]
    public ErrorHandler ErrorHandler { get; set; }

    protected override async Task OnInitializedAsync()
    {
        try
        {
            Model = await _httpService.GetAsync<List<ExaminedNormalListModel>>("api/perfections/GetRecentlyEditList");

        }
        catch (Exception ex)
        {
            await ErrorHandler.ProcessError(ex, "获取近期编辑列表失败");
        }
    }


    public async Task GetNewRandomList()
    {
        await OnInitializedAsync();
    }



}
